package com.sky.controller.admin;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetMealService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author 符健清
 * @version 1.0
 * 套餐控制器
 */
@SuppressWarnings({"all"})
@RestController
@RequestMapping("/admin/setmeal")
@Slf4j
@Api(tags = "套餐 接口")
public class SetMealcontroller {
    @Autowired
    private SetMealService setMealService;
    /**
     * 分页条件查询 套餐 表格
     */
    @ApiOperation("分页条件查询")
    @GetMapping("/page")
    public Result<PageResult>  pageSelectSetMeal(@RequestParam(defaultValue = "1")  Integer page ,
                                                        @RequestParam  (defaultValue = "10") Integer pageSize ,
                                                     Long categoryId ,  String name ,Integer status) {
        log.info("page:{} ,pageSize:{} , categoryid:{} ,name:{} ,status:{}",page,pageSize,categoryId,name,status);
        SetmealPageQueryDTO setmealPageQueryDTO = new SetmealPageQueryDTO();
        setmealPageQueryDTO.setCategoryId(categoryId);
        setmealPageQueryDTO.setName(name);
        setmealPageQueryDTO.setStatus(status);
        setmealPageQueryDTO.setPage(page);
        setmealPageQueryDTO.setPageSize(pageSize);
//       日志输出
        log.info("setmealPageQueryDTO:{}",setmealPageQueryDTO);
             PageResult pageResult =  setMealService.pageSelectSetMeal(setmealPageQueryDTO);
        Result<Object> result = new Result<>();
        return  result.success(pageResult);
    }

    /**
     *  起售 /停售
     *
     */
    @ApiOperation("起售 / 停售")
    @PostMapping("/status/{status}")
    public Result   startAndStopSetmeal (@PathVariable  Integer  status, @RequestParam Integer id  )  {
        log.info(" id:{} , status:{}" , id,status);
        setMealService.startAndStopSetmeal(status,id );
        Result<Object> result = new Result<>();
          return  result.success();
    }

    /**
     * 删除套餐
     */
    @ApiOperation("批量删除套餐")
    @DeleteMapping
    public  Result   deleteSetmeal (@RequestParam  List<Integer> ids)   {
       log.info("ids:{}" ,ids);
       setMealService.deleteSetmeal(ids);
        Result<Object> result = new Result<>();
        return result.success();
    }

    /**
     *   新增套餐
     */
    @ApiOperation("新增套餐")
    @PostMapping
    public Result   addSetmeal (@RequestBody SetmealDTO  setmealDTO){
        log.info("setmealDTO:{}" ,setmealDTO);
        setMealService.insertSetmeal(setmealDTO);
        Result<Object> result = new Result<>();
        return  result.success();
    }

    /**
     * 根据id 查询套餐
     */
    @ApiOperation("根据id 查询套餐")
    @GetMapping("/{id}")
    public Result<SetmealDTO>  selectSetmealById(@PathVariable   Integer id ){
        log.info(" 查询 id:{}  号 套餐",id);
           SetmealDTO setmealDTO  =  setMealService.selectSetmealById(id);
        Result<SetmealDTO> setmealDTOResult = new Result<>();
        return  setmealDTOResult.success(setmealDTO);
    }

    /**
     * 修改套餐
     */
    @ApiOperation("修改套餐")
    @PutMapping
    public Result  updateSetmeal ( @RequestBody SetmealDTO  setmealDTO){
        log.info("setmealDTO:{}" ,setmealDTO);
        setMealService.updateSetmeal(setmealDTO);
        Result<Object> result = new Result<>();
        return result.success();
    }
}

